/*
Class Name      : CasesList
Created by      : Sreekanth SV Vegi
Created On      : 05/02/2013
Description     : This class helps to display all the related cases in queues related to advisor in one section and 
                  queues that are not related to advisor in another section   
Version         : 1.0  
               
*/

public class CasesList
{
    List<Case> AdvisorCasesList=new List<Case>();
    List<Case> NonAdvisorCasesList=new List<Case>();
    public ID AccountIdAssociatedToCase;
    public ID LeadIdAssociatedToCase;
    Public boolean IsThereAnyCaseAssociatedToAccount{set;get;}
    Public boolean IsThereAnyCaseAssociatedToAccount1{set;get;}  
    public String MessageToShowStr{set;get;}
    
    //Constructor 
    public CasesList()
    {
       ID id = ApexPages.currentPage().getParameters().get('id');
       MessageToShowStr='There are no cases to display';
      
       //Query to get Cases list for a specific Account
       try
       {
               Case CaseDetailsObj=new Case();
               IsThereAnyCaseAssociatedToAccount=false;
               IsThereAnyCaseAssociatedToAccount1=false; 
               
        
               if ( ID!=null){
                        
                        
                       CaseDetailsObj=[select Case.Account.id,Case.Lead__c from case 
                                                where id=:id];
                                
                       AccountIdAssociatedToCase=CaseDetailsObj.AccountId;
                       LeadIdAssociatedToCase=CaseDetailsObj.Lead__c;
                       Set<Id> QueueIdsList=GeneralUtilWCM.getQueueIdNotADAorODM();
                         Set<Id>  NONQueueIdsList=GeneralUtilWCM.getNotADAODMQueueIdsList(); 
                           
                       AdvisorCasesList= [SELECT Id,CaseNumber,Subject,Description,Notes__c,Next_Call__c FROM Case 
                                                      where ((Case.Account.id=:AccountIdAssociatedToCase and Case.Lead__c=:LeadIdAssociatedToCase)
                                                               and recordtypeid =:GeneralUtilWCM.getRecordType()
                                                               and Status!='Closed'
                                                               and  (OwnerId=:UserInfo.getUserId()
                                                               or OwnerId IN :QueueIdsList))
                                                               Order by Createddate desc ];
                                                               
               List<ID> UserCases=new List<ID>();
                 for(Case objCase: AdvisorCasesList){
                         UserCases.add(objCase.ID);
                
                    }
                       NonAdvisorCasesList=[SELECT Id,CaseNumber,Subject,Description,Notes__c,Next_Call__c FROM Case 
                                                      where ((Case.Account.id=:AccountIdAssociatedToCase and Case.Lead__c=:LeadIdAssociatedToCase)
                                                           and recordtypeid =:GeneralUtilWCM.getRecordType()
                                                           and Status!='Closed'
                                                           and  ID NOT in :UserCases
                                                           and OwnerId IN:NONQueueIdsList)
                                                                
                                                               Order by Createddate desc ];
                                                   
        
                       if( AdvisorCasesList.size()>0)
                                 IsThereAnyCaseAssociatedToAccount=true;
                       if(NonAdvisorCasesList.size()>0)
                                 IsThereAnyCaseAssociatedToAccount1=true;
                }
      
       }
       catch(Exception e)
       {
       System.debug(e.getMessage());
       }
    }
    
    //Method returns cases list in advisor queues to visualforce page
    public List<Case> getAdvisorCasesList()
    {
        return  AdvisorCasesList;
    }
    
    //Method returns other cases list(not in advisor queues) 
    public List<Case> getNonAdvisorCasesList()
    {
        return NonAdvisorCasesList;
    }
    
    /*public PageReference save()
    {
    PageReference pg=new PageReference('');
    return pg;
    }
    */
}